#!/usr/bin/python3
# @Time    : 2018/6/3 下午 17:04:49  
# @Author  : LaoJI

from app import mongo


class MongoCrud:

    @staticmethod
    def get(examid):
        exam = mongo.db.questions.find_one({'examid': int(examid)})
        if exam is not None:
            exam.pop('_id')
            return dict(success=True, exam=exam)
        return dict(success=False, message='No record found')

    def delete(self, name):
        result = mongo.db.users.delete_one({'name': name})
        count = result.deleted_count
        if count > 0:
            return dict(result='success', message='%d records deleted' % count)
        return dict(result='error', message='Failed to delete')
